package com.neu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.neu.base.Result;
import com.neu.entity.Task;

import com.neu.service.ProjectRskService;
import com.neu.service.impl.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/workloadProcess")
@Tag(name = "进度管理")
public class ProcessController {

    @Autowired
    private PDRServiceImpl pdrService;

    @Autowired
    private RDFServiceImpl rdfService;

    @Autowired
    private SWFServiceImpl swfService;

    @Autowired
    private ProjectRskService projectRskService;

    @Autowired
    private CostServiceImpl costService;

    @Autowired
    private TaskServiceImpl taskService;


    @PostMapping("/get")
    @Operation(summary = "获取进程信息")
    public Result getProcess(@RequestParam String id){
        Map map = new HashMap<>();
        Process data = new Process();

        data.pdr_process = pdrService.getById(id).getProgress()*100;
        data.rdf_process = rdfService.getById(id).getProgress()*100;
        data.swf_process = swfService.getById(id).getProgress()*100;
        data.rsk_process = projectRskService.getById(id).getProgress()*100;
        data.cost_process = costService.getById(id).getProgress()*100;

        data.total_process = (pdrService.getById(id).getProgress()+rdfService.getById(id).getProgress()+
                swfService.getById(id).getProgress()+projectRskService.getById(id).getProgress()+costService.getById(id).getProgress()) *100 / 5 ;
        QueryWrapper<Task> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .eq("project_id", id)           // 等于条件
                .eq("task_type",2);        // IN 条件

        Task task = taskService.getOne(queryWrapper);
        task.setProgress(data.total_process);
        taskService.updateById(task);

        map.put("data",data);
        map.put("task",task);

        return Result.success(map);
    }

    class Process{
        public Integer pdr_process;
        public Integer rdf_process;
        public Integer swf_process;
        public Integer rsk_process;
        public Integer cost_process;
        public Integer total_process;
    }

}
